/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package canteen.sys.model.entity.repository;

import canteen.sys.model.entity.EmployeeMaster;
import canteen.sys.model.generic.GenericHibernateDAOSupport;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author TNT
 */
public class EmployeeMasterDAOImpl extends GenericHibernateDAOSupport<EmployeeMaster, Long> implements EmployeeMasterDAO {

    @Override
    public EmployeeMaster findEmployeeByUserId(int userId) {
        List<EmployeeMaster> listEm;
        EmployeeMaster em = null;
        Transaction transaction = getSession().beginTransaction();
        try {
            listEm = getSession().createCriteria(EmployeeMaster.class)
                    .add(Restrictions.eq("loginMaster.lId", userId)).list();
            transaction.commit();
            if (listEm.size() > 0) {
                em = listEm.get(0);
            }
        } catch (HibernateException ex) {
            transaction.rollback();
        }
        return em;
    }
}
